package rge.orumus.encdb;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class EncDBHelper extends SQLiteOpenHelper {
	
	static final String dbName="encWalletDB";
	static final int dbVersion = 1;
	
	static final String encRecordsTable="EncRecords";
	static final String colIndex="RecordIndex";
	static final String colTitle="Title";
	static final String colType="Type";
	static final String colData="Data";

	static final String viewEmps="ViewEmps";
	
	public EncDBHelper(Context context) {
		super(context, dbName, null, dbVersion);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		  db.execSQL("CREATE TABLE " + encRecordsTable 
				       + " (" + colIndex + " INTEGER PRIMARY KEY AUTOINCREMENT, "
				              + colTitle + " TEXT, "
				              + colType + " TEXT, "
				              + colData + " TEXT )");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		  db.execSQL("DROP TABLE IF EXISTS " + encRecordsTable);
		  onCreate(db);
	}
	
	@Override
	public void onOpen(SQLiteDatabase db) {
		super.onOpen(db);
	}
	
	public Cursor getHeaders(){
		SQLiteDatabase db = this.getReadableDatabase();
		Cursor cur=db.rawQuery("SELECT "
								+ colIndex + " as _index, "
								+ colTitle + " as _title, "
								+ colType + " _type " 
								+ " from " + encRecordsTable, new String [] {});
		return cur;
	}
	
	
	public void insertRecord(String title, String type, String data){
		SQLiteDatabase db = this.getWritableDatabase();
		ContentValues cv = new ContentValues();
		cv.put(colTitle, title);
		cv.put(colType, type);
		cv.put(colData, data);
		db.insert(encRecordsTable, null, cv);
		db.close();
	}
}
